//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "ATTraining\fn_targetShot.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_target","_distance","_damage","_shooter","_feedback_id"];
DEFAULT_PARAM(_shooter,0,objNull);
DEFAULT_PARAM(_damage,1,0);
DEFAULT_PARAM(_distance,2,0);
DEFAULT_PARAM(_target,3,objNull);

if (isServer && {!isnull _shooter}) then {
	private ["_corrected_dist","_score"];
	_corrected_dist = (floor(_distance / 100)) max 1;
	_score = ((floor(10 * _damage)) min 10) * _corrected_dist;
	_shooter addScore _score;
};

if (!isDedicated && {alive player} && {!isnull _shooter} && {player == _shooter}) then {
	private ["_feedback","_shot_type","_procent_dmg","_target_name"];
	_procent_dmg = (round(100 * _damage)) min 100;
	_shot_type = switch (true) do {
		case (_damage >= 0.8): { localize "STR_AT_DESTRUCTIVE_SHOT" };
		case (_damage >= 0.45): { localize "STR_AT_GOOD_SHOT" };
		default { localize "STR_AT_WEAK_SHOT" };
	};
	_target_name = getText(configFile/"CfgVehicles"/(typeof _target)/"DisplayName");
	_feedback = parseText format[localize "STR_AT_FEEDBACK",_shot_type,_procent_dmg,_distance,_target_name,"%"];
	GVAR(FEEDBACK_ID) = GVAR(FEEDBACK_ID) + 1;
	_feedback_id = GVAR(FEEDBACK_ID);
	[_feedback_id, _feedback] spawn {
		private ["_feedback_id","_feedback","_end"];
		_feedback_id = _this select 0;
		_feedback = _this select 1;
		_end = time + 5;
		waituntil { sleep 0.345; if (_feedback_id == GVAR(FEEDBACK_ID)) then { hintSilent _feedback; }; time >= _end || _feedback_id != GVAR(FEEDBACK_ID)};
	};
};

TRACE("End");
TMFPROFILERSTOP;
